Merge conflicts solutioned
[RRRRHHHH_Code] / ruralHouses client / src / gui / OwnerRegistrationGUI.java
diff --git a/ruralHouses client/src/gui/OwnerRegistrationGUI.java b/ruralHouses client/src/gui/OwnerRegistrationGUI.java
new file mode 100644 (file)
index 0000000..fad1933
--- /dev/null
@@ -0,0 +1,158 @@
+package gui;
+
+import java.awt.Color;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.rmi.Naming;
+import java.rmi.RemoteException;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.border.EmptyBorder;
+
+import common.AdminInterface;
+
+import configuration.___IntNames;
+import domain.Account;
+import domain.Owner;
+
+public class OwnerRegistrationGUI extends JFrame {
+
+       private JPanel panel;
+       private JTextField nameField;
+       private JTextField userNameField;
+       private AdminInterface am = null;
+       private JTextField passField;
+       private JTextField bank1Field;
+       private JTextField bank2Field;
+       private JTextField bank3Field;
+       private JTextField bank4Field;
+       private JTextField emailField;
+       private JLabel lblWhenAcceptedYou;
+       private JLabel feedback;
+
+       /**
+        * Create the frame.
+        */
+       public OwnerRegistrationGUI() {
+               
+               try {
+                       am = (AdminInterface) Naming
+                                       .lookup(___IntNames.AdminManager);
+               } catch (Exception e1) {
+                       System.out.println("Error accessing remote authentication: "
+                                       + e1.toString());
+               }
+               setTitle("Owner registration");
+               setBounds(100, 100, 500, 400);
+               panel = new JPanel();
+               panel.setBorder(new EmptyBorder(5, 5, 5, 5));
+               setContentPane(panel);
+               panel.setLayout(null);
+
+               JLabel nameLb = new JLabel("Name:");
+               nameLb.setBounds(37, 45, 46, 14);
+               panel.add(nameLb);
+
+               nameField = new JTextField();
+               nameField.setBounds(147, 42, 86, 20);
+               panel.add(nameField);
+               nameField.setColumns(10);
+
+               JLabel lblUsername = new JLabel("Username:");
+               lblUsername.setBounds(37, 212, 69, 14);
+               panel.add(lblUsername);
+
+               userNameField = new JTextField();
+               userNameField.setBounds(147, 209, 86, 20);
+               panel.add(userNameField);
+               userNameField.setColumns(10);
+
+               JLabel lblPassword = new JLabel("Password:");
+               lblPassword.setBounds(37, 258, 69, 14);
+               panel.add(lblPassword);
+
+               passField = new JTextField();
+               passField.setBounds(147, 255, 86, 20);
+               panel.add(passField);
+               passField.setColumns(10);
+
+               JLabel lblBankAccount = new JLabel("Bank account:");
+               lblBankAccount.setBounds(37, 94, 69, 14);
+               panel.add(lblBankAccount);
+
+               bank1Field = new JTextField();
+               bank1Field.setBounds(147, 91, 61, 20);
+               panel.add(bank1Field);
+
+               bank2Field = new JTextField();
+               bank2Field.setBounds(218, 91, 61, 20);
+               panel.add(bank2Field);
+
+               bank3Field = new JTextField();
+               bank3Field.setBounds(289, 91, 32, 20);
+               panel.add(bank3Field);
+
+               bank4Field = new JTextField();
+               bank4Field.setBounds(331, 91, 117, 20);
+               panel.add(bank4Field);
+
+               JButton btnSendRegistrationRequest = new JButton(
+                               "Send registration request");
+               btnSendRegistrationRequest.setBounds(127, 316, 194, 23);
+               btnSendRegistrationRequest.addActionListener(new ActionListener() {
+                       public void actionPerformed(ActionEvent arg0) {
+
+                               jButton_ActionPerformed(arg0);
+                       }
+               });
+
+               panel.add(btnSendRegistrationRequest);
+
+               JLabel lblEmail = new JLabel("E-mail:");
+               lblEmail.setBounds(37, 155, 46, 14);
+               panel.add(lblEmail);
+
+               emailField = new JTextField();
+               emailField.setBounds(147, 152, 148, 20);
+               panel.add(emailField);
+               emailField.setColumns(10);
+
+               lblWhenAcceptedYou = new JLabel(
+                               "When accepted you will receive an e-mail");
+               lblWhenAcceptedYou.setForeground(Color.GREEN);
+               lblWhenAcceptedYou.setBounds(127, 291, 214, 14);
+               panel.add(lblWhenAcceptedYou);
+
+               feedback = new JLabel("");
+               feedback.setForeground(Color.RED);
+               feedback.setEnabled(false);
+               feedback.setBounds(127, 344, 214, 20);
+               panel.add(feedback);
+       }
+
+       private void jButton_ActionPerformed(ActionEvent e) {
+
+               Owner own = new Owner(this.nameField.getText(),
+                               this.bank1Field.getText() + " " + this.bank2Field.getText()
+                                               + " " + this.bank3Field.getText() + " "
+                                               + this.bank4Field.getText(), this.emailField.getText());
+               Account acc = new Account(this.userNameField.getText(),
+                               this.passField.getText(), own);
+
+               try {
+                       if (this.am.addAccount(acc)) {
+                               this.feedback.setText("Request sended");
+                       } else {
+                               this.feedback.setText("Can't send the request");
+                       }
+               } catch (RemoteException e1) {
+                       // TODO Auto-generated catch block
+                       e1.printStackTrace();
+               }
+
+       }
+}